From 72c0ce43a854d5cd5601d1d19423518065ce33ff Mon Sep 17 00:00:00 2001 From: Ori Livneh Date: Tue, 6 May 2014 02:31:24 -0700 Subject: [PATCH] Add $wgServerName This partially reverts r73950 which removed $wgServerName on the ground that it was only used for {{SERVERNAME}}. When it was pointed out that $wgServerName was also used by several extensions, the response was not to restore the variable, but to proceed to remove it from extensions as well. It is a useful variable to have, as the discussion on Id819246a9 makes clear (see Tim's comment on PS12 and Timo's reply). So let's reintroduce it, and expose it in mw.config and ApiQuerySiteInfo as well. Change-Id: I40a6fd427d38c64c628f70a2f407b145443ea204 --- RELEASE-NOTES-1.24 | 2 ++ includes/DefaultSettings.php | 18 ++++++++---- includes/Setup.php | 28 ++++++++++++++++--- includes/api/ApiQuerySiteinfo.php | 1 + includes/parser/Parser.php | 5 ++-- .../ResourceLoaderStartUpModule.php | 5 ++-- tests/parser/parserTest.inc | 1 + .../phpunit/includes/parser/NewParserTest.php | 1 + 8 files changed, 47 insertions(+), 14 deletions(-) diff --git a/RELEASE-NOTES-1.24 b/RELEASE-NOTES-1.24 index 5185517eb0..536e6e6aae 100644 --- a/RELEASE-NOTES-1.24 +++ b/RELEASE-NOTES-1.24 @@ -9,6 +9,8 @@ MediaWiki 1.24 is an alpha-quality branch and is not recommended for use in production. === Configuration changes in 1.24 === +* The server's canonical hostname is available as $wgServerName, which is + exposed in both mw.config and ApiQuerySiteInfo. === New features in 1.24 === * Added a new hook, "WhatLinksHereProps", to allow extensions to annotate diff --git a/includes/DefaultSettings.php b/includes/DefaultSettings.php index 2b8aec39f6..c6f48a74f4 100644 --- a/includes/DefaultSettings.php +++ b/includes/DefaultSettings.php @@ -104,6 +104,13 @@ $wgServer = WebRequest::detectServer(); */ $wgCanonicalServer = false; +/** + * Server name. This is automatically computed by parsing the bare + * hostname out of $wgCanonicalServer. It should not be customized. + * @since 1.24 + */ +$wgServerName = false; + /************************************************************************//** * @name Script path settings * @{ @@ -1304,21 +1311,22 @@ $wgDjvuOutputExtension = 'jpg'; * @{ */ -$serverName = substr( $wgServer, strrpos( $wgServer, '/' ) + 1 ); /** * Site admin email address. + * + * Defaults to "wikiadmin@{$wgServerName}". */ -$wgEmergencyContact = 'wikiadmin@' . $serverName; +$wgEmergencyContact = false; /** * Password reminder email address. * * The address we should use as sender when a user is requesting his password. + * + * Defaults to "apache@{$wgServerName}". */ -$wgPasswordSender = 'apache@' . $serverName; - -unset( $serverName ); # Don't leak local variables to global scope +$wgPasswordSender = false; /** * Password reminder name diff --git a/includes/Setup.php b/includes/Setup.php index b155f90450..18d1e337e4 100644 --- a/includes/Setup.php +++ b/includes/Setup.php @@ -43,6 +43,7 @@ if ( !isset( $wgVersion ) ) { } // Set various default paths sensibly... + if ( $wgScript === false ) { $wgScript = "$wgScriptPath/index$wgScriptExtension"; } @@ -420,6 +421,29 @@ require_once "$IP/includes/normal/UtfNormalDefines.php"; wfProfileOut( $fname . '-includes' ); wfProfileIn( $fname . '-defaults2' ); + +if ( $wgCanonicalServer === false ) { + $wgCanonicalServer = wfExpandUrl( $wgServer, PROTO_HTTP ); +} + +// Set server name +$serverParts = wfParseUrl( $wgCanonicalServer ); +if ( $wgServerName !== false ) { + wfWarn( '$wgServerName should be derived from $wgCanonicalServer, not customized. Overwriting $wgServerName.' ); +} +$wgServerName = $serverParts['host']; +unset( $serverParts ); + +// Set defaults for configuration variables +// that are derived from the server name by default +if ( $wgEmergencyContact === false ) { + $wgEmergencyContact = 'wikiadmin@' . $wgServerName; +} + +if ( $wgPasswordSender === false ) { + $wgPasswordSender = 'apache@' . $wgServerName; +} + if ( $wgSecureLogin && substr( $wgServer, 0, 2 ) !== '//' ) { $wgSecureLogin = false; wfWarn( 'Secure login was enabled on a server that only supports HTTP or HTTPS. Disabling secure login.' ); @@ -433,10 +457,6 @@ if ( $wgTmpDirectory === false ) { wfProfileOut( $fname . '-tempDir' ); } -if ( $wgCanonicalServer === false ) { - $wgCanonicalServer = wfExpandUrl( $wgServer, PROTO_HTTP ); -} - // $wgHTCPMulticastRouting got renamed to $wgHTCPRouting in MediaWiki 1.22 // ensure back compatibility. if ( !$wgHTCPRouting && $wgHTCPMulticastRouting ) { diff --git a/includes/api/ApiQuerySiteinfo.php b/includes/api/ApiQuerySiteinfo.php index b0e9bd227e..d3d61a4b06 100644 --- a/includes/api/ApiQuerySiteinfo.php +++ b/includes/api/ApiQuerySiteinfo.php @@ -239,6 +239,7 @@ class ApiQuerySiteinfo extends ApiQueryBase { $data['script'] = $GLOBALS['wgScript']; $data['variantarticlepath'] = $GLOBALS['wgVariantArticlePath']; $data['server'] = $GLOBALS['wgServer']; + $data['servername'] = $GLOBALS['wgServerName']; $data['wikiid'] = wfWikiID(); $data['time'] = wfTimestamp( TS_ISO_8601, time() ); diff --git a/includes/parser/Parser.php b/includes/parser/Parser.php index 7423006788..29b14dee91 100644 --- a/includes/parser/Parser.php +++ b/includes/parser/Parser.php @@ -2731,7 +2731,7 @@ class Parser { * @return string */ function getVariableValue( $index, $frame = false ) { - global $wgContLang, $wgSitename, $wgServer; + global $wgContLang, $wgSitename, $wgServer, $wgServerName; global $wgArticlePath, $wgScriptPath, $wgStylePath; if ( is_null( $this->mTitle ) ) { @@ -3032,8 +3032,7 @@ class Parser { case 'server': return $wgServer; case 'servername': - $serverParts = wfParseUrl( $wgServer ); - return $serverParts && isset( $serverParts['host'] ) ? $serverParts['host'] : $wgServer; + return $wgServerName; case 'scriptpath': return $wgScriptPath; case 'stylepath': diff --git a/includes/resourceloader/ResourceLoaderStartUpModule.php b/includes/resourceloader/ResourceLoaderStartUpModule.php index d0f05416f8..f9c5057709 100644 --- a/includes/resourceloader/ResourceLoaderStartUpModule.php +++ b/includes/resourceloader/ResourceLoaderStartUpModule.php @@ -44,8 +44,8 @@ class ResourceLoaderStartUpModule extends ResourceLoaderModule { } global $wgLoadScript, $wgScript, $wgStylePath, $wgScriptExtension, - $wgArticlePath, $wgScriptPath, $wgServer, $wgContLang, - $wgVariantArticlePath, $wgActionPaths, $wgVersion, + $wgArticlePath, $wgScriptPath, $wgServer, $wgServerName, + $wgContLang, $wgVariantArticlePath, $wgActionPaths, $wgVersion, $wgEnableAPI, $wgEnableWriteAPI, $wgDBname, $wgSitename, $wgFileExtensions, $wgExtensionAssetsPath, $wgCookiePrefix, $wgResourceLoaderMaxQueryLength, @@ -85,6 +85,7 @@ class ResourceLoaderStartUpModule extends ResourceLoaderModule { // becoming [] instead of {} in JS (bug 34604) 'wgActionPaths' => (object)$wgActionPaths, 'wgServer' => $wgServer, + 'wgServerName' => $wgServerName, 'wgUserLanguage' => $context->getLanguage(), 'wgContentLanguage' => $wgContLang->getCode(), 'wgVersion' => $wgVersion, diff --git a/tests/parser/parserTest.inc b/tests/parser/parserTest.inc index b4e903d633..1875ac5cca 100644 --- a/tests/parser/parserTest.inc +++ b/tests/parser/parserTest.inc @@ -763,6 +763,7 @@ class ParserTest { $settings = array( 'wgServer' => 'http://example.org', + 'wgServerName' => 'example.org', 'wgScript' => '/index.php', 'wgScriptPath' => '/', 'wgArticlePath' => '/wiki/$1', diff --git a/tests/phpunit/includes/parser/NewParserTest.php b/tests/phpunit/includes/parser/NewParserTest.php index 66ed020a52..14bcac097a 100644 --- a/tests/phpunit/includes/parser/NewParserTest.php +++ b/tests/phpunit/includes/parser/NewParserTest.php @@ -65,6 +65,7 @@ class NewParserTest extends MediaWikiTestCase { $tmpGlobals['wgContLang'] = Language::factory( 'en' ); $tmpGlobals['wgSitename'] = 'MediaWiki'; $tmpGlobals['wgServer'] = 'http://example.org'; + $tmpGlobals['wgServerName'] = 'example.org'; $tmpGlobals['wgScript'] = '/index.php'; $tmpGlobals['wgScriptPath'] = '/'; $tmpGlobals['wgArticlePath'] = '/wiki/$1'; -- 2.20.1